#!/usr/bin/env python 
# encoding: utf-8 
# @Author: Jacqueline
# @file: 06窗口管理.py
# @time: 2021/2/23 15:21
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
#打开新窗口
driver = webdriver.Chrome()
driver.implicitly_wait(3)





def open_new_window_and_switch(url):
    """打开新窗口打开页面并切换"""
    old_win = driver.window_handles()
    js = 'windom.open("arguments[0]")'
    driver.execute_script(js, url)
    # 等待新窗口打开
    WebDriverWait(driver, 10, 0.5).until(
        EC.new_window_is_opened(old_win)
    )
    new_wins = driver.window_handles
    driver.switch_to_window(new_wins[-1])

    driver.find_element_by_id('kw').send_keys('python')
    pass

open_new_window_and_switch(driver,'https://www.baidu.com')